﻿using System;
using System.Windows;
using System.Windows.Data;

namespace Rio.Manager.Application.Converters
{
    /// <summary>
    ///     Two way IValueConverter that lets you bind the inverse of a boolean property
    ///     to a dependency property
    /// </summary>
    public class NotOperatorValueConverter : IValueConverter
    {
        #region Methods

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is bool)
            {
                return !( (bool)value );
            }
            else if (value is Visibility)
            {
                Visibility v = (Visibility)value;

                return v == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed;
            }
            else
            {
                throw new Exception("Type not found.");
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is bool)
            {
                return !( (bool)value );
            }
            else if (value is Visibility)
            {
                Visibility v = (Visibility)value;

                return v == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed;
            }
            else
            {
                throw new Exception("Type not found.");
            }
        }

        #endregion Methods
    }
}